﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Service.ZSJL.Com.Security
{
    public class Base64Encode : IEncrypt
    {
        public string EnCode(string source)
        {
            byte[] bytes = Encoding.Default.GetBytes(source);
            return Convert.ToBase64String(bytes);
        }

        public string EnCode(string pToEncrypt, string sKey)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(pToEncrypt);
            byte[] bytes2 = Encoding.UTF8.GetBytes(sKey);
            return Convert.ToBase64String(bytes) + Convert.ToBase64String(bytes2);
        }

        public string DeCode(string source)
        {
            byte[] outputb = Convert.FromBase64String(source);
            return Encoding.UTF8.GetString(outputb);
        }

        public string DeCode(string pToEncrypt, string sKey)
        {
            byte[] bytes2 = Encoding.UTF8.GetBytes(sKey);
            string str = Convert.ToBase64String(bytes2);

            pToEncrypt = pToEncrypt.Replace(str, "");
            byte[] outputb2 = Convert.FromBase64String(pToEncrypt);
            return Encoding.UTF8.GetString(outputb2);
        }
    }
}
